package com.ming.stringstudy.feedbacksystem.controller;

import com.ming.stringstudy.feedbacksystem.entity.Reply;
import com.ming.stringstudy.feedbacksystem.pojo.Result;
import com.ming.stringstudy.feedbacksystem.service.IReplyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 回复意见/问题表 前端控制器
 * </p>
 *
 * @author aming
 * @since 2024-12-24
 */
@Slf4j
@RestController
@RequestMapping("/replys")
public class ReplyController {
    @Autowired
    IReplyService replyService;


    @PostMapping
    public Result insertReplyService(@RequestBody Reply reply
                                    ,@RequestAttribute("userId") Integer userId) {
        reply.setUserId(userId);
        log.info(reply.toString());
        Boolean state = replyService.insertReplyService(reply);
        if(state) {
            return Result.success();
        }else{
            return Result.error("该问题已被归档/退回了/这个问题根本不存在");
        }
    }

    @GetMapping("/{commentId}")
    public Result selectReplyList(@PathVariable Integer commentId) {
        log.info(commentId.toString());
        List<Reply> replies = replyService.selectReplyList(commentId);
        return Result.success(replies);
    }

}
